import request from '@/router/axios';

// 备料单分页接口
export const getList = (current, size, params) => {
  return request({
    url: `/api/mes-warehouse/preparation-order/page`,
    method: 'get',
    params: {
      ...params,
      current,
      size
    }
  });
};
export const update = (preparationOrderId, remark) => {
  return request({
    url: '/api/mes-warehouse/preparation-order/edit',
    method: 'post',
    data: {
      preparationOrderId,
      remark
    }
  });
};
// 备料单详情接口
export const getDetail = (id) => {
  return request({
    url: '/api/mes-warehouse/preparation-order/detail',
    method: 'get',
    params: {
      id
    }
  });
};

// 备料单详情备料明细分页接口
export const getDetailPageList = (current, size, sheetId) => {
  return request({
    url: `/api/mes-warehouse/prepare-material/detail-page`,
    method: 'get',
    params: {
      current,
      size,
      sheetId
    }
  });
};

// 备料单详情备料明细不分页接口
export const getDetailAllList = (sheetId) => {
  return request({
    url: `/api/mes-warehouse/prepare-material/detail-list`,
    method: 'get',
    params: {
      sheetId
    }
  });
};

// 包装详情接口
export const getPackBoxDetail = (sheetHeaderId) => {
  return request({
    url: '/api/mes-warehouse/sheet/packing/list-by-sheet-header-id',
    method: 'get',
    params: {
      sheetHeaderId,
      action: 'PICKING'
    }
  });
};

// 拆包明细
export const getUnpackDetail = (sheetHeaderId) => {
  return request({
    url: '/api/mes-warehouse/unpacking/detail/list-by-sheet-header-id',
    method: 'get',
    params: {
      sheetHeaderId
    }
  });
};

// 合并撤销
export const cancelMerge = (data) => {
  return request({
    url: '/api/mes-warehouse/flow/execute',
    method: 'post',
    data
  });
};

// 拆分撤销
export const cancelSplit = (data) => {
  return request({
    url: '/api/mes-warehouse/flow/execute',
    method: 'post',
    data
  });
};

// 备料分析规则保存
export const submitRule = (data) => {
  return request({
    url: '/api/mes-warehouse/part-preparation-rule/submit',
    method: 'post',
    data
  });
};
// 备料分析规则查看
export const searchRule = () => {
  return request({
    url: '/api/mes-warehouse/part-preparation-rule/detail',
    method: 'get'
  });
};

// 备料单新增 下一步
export const nextStep = (data) => {
  return request({
    url: '/api/mes-warehouse/preparation-order/analysis',
    method: 'post',
    data
  });
};
// 备料单新增 分析推荐批次
export const nextRecommendLotNo = (data) => {
  return request({
    url: '/api/mes-warehouse/preparation-order/recommendLotNo',
    method: 'post',
    data
  });
};
// 备料单新增 提交
export const analysisSubmit = (data) => {
  return request({
    url: '/api/mes-warehouse/preparation-order/analysis-submit',
    method: 'post',
    data
  });
};
// 备料单新增接口
export const flowExecute = (data) => {
  return request({
    url: '/api/mes-warehouse/flow/execute',
    method: 'post',
    data
  });
};

// 获取线边仓列表
export const getMaterialList = (params) => {
  return request({
    url: '/api/mes-admin/inventory/list',
    method: 'get',
    params: params
  });
};

// 备料单拆分
export const prepareSplits = (preparationOrderNo) => {
  return request({
    url: '/api/mes-warehouse/preparation-order/split?preparationOrderNo=' + preparationOrderNo,
    method: 'post'
  });
};

// 备料单拆分提交
export const prepareSplitsSubmit = (data) => {
  return request({
    url: '/api/mes-warehouse/preparation-order/split/submit',
    method: 'post',
    data
  });
};

// 详情-物料明细
export const getMaterialInfoById = (current, size, preparationOrderNo, warehouseType) => {
  return request({
    url: '/api/mes-warehouse/preparation-order-detail/page',
    method: 'get',
    params: {
      preparationOrderNo: preparationOrderNo,
      warehouseType: warehouseType,
      current,
      size
    }
  });
};

// 获取合并备料单已选中列表
export const getSheetheaderPage = (data) => {
  return request({
    url: '/api/mes-warehouse/v2/sheetheader/page',
    method: 'post',
    data
  });
};

// 根据线边仓id和物料编码获取线边仓裕量等
export const getAnalysisForLineSide = (data) => {
  return request({
    url: '/api/mes-warehouse/prepare-analysis/get-analysis-for-line-side',
    method: 'post',
    data
  });
};

export const getAnalysisListForLineSide = (data) => {
  return request({
    url: '/api/mes-warehouse/prepare-analysis/get-analysis-list-for-line-side',
    method: 'post',
    data
  });
};

// 备料 - 单行明细分析

export const singleRowPrepareAnalysis = (data) => {
  return request({
    url: '/api/mes-warehouse/prepare-analysis/get-analysis',
    method: 'post',
    data
  });
};

// 获取物料编码超收数量
export const getOverListByPartNo = (partNo) => {
  return request({
    url: '/api/mes-warehouse/prepare-analysis/get-analysis-over-list',
    method: 'get',
    params: {
      partNo: partNo
    }
  });
};

// 修改之后的备料单详情
export const updateOverList = (data) => {
  return request({
    url: '/api/mes-warehouse/prepare-analysis/update-analysis-over-list',
    method: 'post',
    data
  });
};

// 欠料分析
export const unfeedAnalysis = (data) => {
  return request({
    url: '/api/mes-warehouse/flow/execute',
    method: 'post',
    data
  });
};

// 备料出库
export const outBound = (data) => {
  return request({
    url: '/api/mes-warehouse/flow/execute',
    method: 'post',
    data
  });
};

// 操作记录
export const getOperationPageList = (current, size, sheetHeaderId) => {
  return request({
    url: `/api/mes-warehouse/sheet-operation/getPage/by-sheet-header-id`,
    method: 'get',
    params: {
      current,
      size,
      sheetHeaderId
    }
  });
};

// 操作记录-打印
export const operationSubmit = (data) => {
  return request({
    url: `/api/mes-warehouse/sheet-operation/submit`,
    method: 'post',
    data
  });
};

// 领料单页面出库弹窗分页
export const getOutboundList = (current, size, params) => {
  return request({
    url: `/api/mes-warehouse/v2/sheetheader/mpl/outbound/page`,
    method: 'post',
    params: {
      current,
      size
    },
    data: {
      ...params
    }
  });
};

// 根据单据id 查询备料单明细
export const getPrepareMaterialDetail = (prepareMaterialSheetHeaderId) => {
  return request({
    url: `/api/mes-warehouse/prepare-material/detail`,
    method: 'get',
    params: {
      prepareMaterialSheetHeaderId
    }
  });
};

export const getWarehouseList = () => {
  return request({
    url: '/api/mes-warehouse/warehouse/list',
    method: 'get'
  });
};

// 合并详情
export const getMergeDetail = (data) => {
  return request({
    url: `/api/mes-warehouse/preparation-order/merge-detail`,
    method: 'post',
    data
  });
};

// 合并物料详情
export const getMaterialMergeDetail = (preparationOrderNo, preparationOrderLot) => {
  return request({
    url: `/api/mes-warehouse/preparation-material-detail/list`,
    method: 'get',
    params: {
      preparationOrderNo,
      preparationOrderLot
    }
  });
};
